const app = getApp()
let qCloud = require("../../../index.js");
Page({

  /**
   * 页面的初始数据
   */
  data: {
    imgPath: qCloud.config.STATIC_IMAGE_PATH,
    procedurearray: [{
        id: 1,
        title: "工序1",
        content: "文本1"
      },
      {
        id: 2,
        title: "工序2",
        content: "文本2"
      },
      {
        id: 3,
        title: "工序3",
        content: "文本3"
      },
      {
        id: 4,
        title: "工序4",
        content: "文本4"
      },
      {
        id: 5,
        title: "工序5",
        content: "文本5"
      },
      {
        id: 6,
        title: "工序6",
        content: "文本6"
      },
      {
        id: 7,
        title: "工序7",
        content: "文本7"
      },
    ]
  },

  checkboxChange(e) {
    const items = this.data.procedurearray
    const values = e.detail.value
    let selected = [];
    for (let i = 0, lenI = items.length; i < lenI; ++i) {
      items[i].checked = false
      for (let j = 0, lenJ = values.length; j < lenJ; ++j) {
        if (items[i].id == values[j]) {
          items[i].checked = true
          selected.push(items[i]);
          break
        }
      }
    }

    this.setData({
      procedurearray: items
    })
    wx.setStorage({
      key: "depart_procedure",
      data: selected
    })
  },
  dosubmit() {
    wx.navigateTo({
      url: "/pages/enterprise/department/adds",
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    let self = this
    wx.getStorage({
      key: "depart_procedure",
      success(res) {
        let data = res.data
        let procedurearray = self.data.procedurearray
        for (let i = 0; i < procedurearray.length; i++) {
          for (let j = 0; j < data.length; j++) {
            if (data[j]["id"] == procedurearray[i]["id"]) {
              procedurearray[i]["checked"] = true;
              break;
            }
          }
        }
        self.setData({
          procedurearray: procedurearray
        })
      }
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
    wx.navigateTo({
      url: "/pages/enterprise/deparment/adds",
    })
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})
